package gui2;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JPanel;

public class OthelloBrick extends JPanel{ 
    
    public Color color = Color.green;
    public int x;
    public int y;
    
    // The brick's position
    public OthelloBrick(int x, int y) { 
        this.x = x;
        this.y = y;
        this.setBackground(Color.green);
        this.setBorder(BorderFactory.createLineBorder(Color.GRAY));        
        
        this.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent me) {                
            }

            @Override
            public void mousePressed(MouseEvent me) {
                
            }

            @Override
            public void mouseReleased(MouseEvent me) {
            }

            @Override
            public void mouseEntered(MouseEvent me) {
            }

            @Override
            public void mouseExited(MouseEvent me) {
            }
        });
    }
    
    public void changeColor(){  
        if(color == color.black)
            color = color.white;
        else if(color == color.white)
            color = color.black;
                    
        repaint();
    }
    
    public void changeColorToSpecific(Color color){    
        this.color = color;
        repaint();
    }
    
    public int GetOwner()
    {
        if(color == Color.white)
            return 2;
        else if(color == Color.black)
            return 1;
        else
            return -1;
    }
    
    @Override
    protected void paintComponent(Graphics g){
        super.paintComponent(g);
        
        int radius = (int)(Math.min(getWidth(), getHeight()) * 0.8 * 0.5);
        int xCenter = getWidth() / 2;
        int yCenter = getHeight() / 2;
        g.setColor(color);
        g.fillOval(xCenter - radius, yCenter - radius, 2 * radius, 2 * radius);
    }
}
